def str2checknum(s: str) -> int:
    LOW_MASK = 0xFFFF
    length = len(s)
    if length & 1:
        s += "\0"
    cks = 0
    i = 0
    while i < length:
        cks += (ord(s[i]) << 8) | (ord(s[i + 1]))
        cks = (cks & LOW_MASK) + (cks >> 16)
        i += 2
    return (~cks) & LOW_MASK

if __name__ == "__main__":
    s = "Internet"
    cks = str2checknum(s)
    print("%d, %x" % (cks,cks))
